/*
 * WidgetClickeable.cpp
 *
 *  Created on: Apr 21, 2012
 *      Author: gonzalo
 */

#include "WidgetClickeable.h"

void WidgetClickeable::init(int posX, int posY)
{
    //Set the surface of the widget, the unpressed one.
    this->surface = unpressedSurface;
    initParcel(posX, posY);
}

WidgetClickeable::WidgetClickeable(Color& color,int width, int height,int posX, int posY, Widget* parent)
:Widget(posX,posY,NULL,parent){

	this->pressedSurface = SurfaceUtils::colorSurface(width,height,color);
	this->unpressedSurface = SurfaceUtils::colorSurface(width,height,*(color.opuesto()));

    init(posX,posY);
}

WidgetClickeable::WidgetClickeable(std::string path,int posX, int posY,  Widget* parent)
:Widget(posX,posY,NULL,parent){

	std::stringstream pressedSurfacePath;
	pressedSurfacePath << IMAGES_DEFAULT_FOLDER << path << IMAGES_DEFAULT_PRESSED;
	std::stringstream unpressedSurfacePath;
	unpressedSurfacePath << IMAGES_DEFAULT_FOLDER << path << IMAGES_DEFAULT_UNPRESSED;

	this->pressedSurface = SurfaceUtils::loadImage(pressedSurfacePath.str());
	this->unpressedSurface = SurfaceUtils::loadImage(unpressedSurfacePath.str());

	init(posX,posY);
}

void WidgetClickeable::resolve() {
	if (this->pressed) {
		this->surface = this->pressedSurface;
	} else if (!this->pressed) {
		this->surface= this->unpressedSurface;
	}
}

WidgetClickeable::~WidgetClickeable(){
	if(this->pressedSurface !=NULL)
		SDL_FreeSurface(this->pressedSurface);

	if(this->unpressedSurface !=NULL)
		SDL_FreeSurface(this->unpressedSurface);
}
